import java.nio.channels.*;

/**
 * @author Team 29
 * This singleton is used by the server to store messages recieved
 * by the ServerGate to be retrieved by Server.
 *
 */
public class ServerMessageHandler implements Runnable{

	private RecievedMessages messagequeue;
	private ServerGate sg;
	
	public ServerMessageHandler(ServerGate s, RecievedMessages rem)
	{
		sg = s;
		messagequeue = rem;
	}
	/**
	 * @param rm
	 * Adds a recieved message to the server's queue for processing.
	 */
	public void forwardMessage(RecievedMessage rm)
	{
		messagequeue.add(rm);
		Logger.log("RECIEVED: "+ rm.message);
		System.out.println(rm.message);
	}//end forward
	

	public void run() {
		while(true)
		{
			sg.listen();
		}
		
	}//end run
}
